#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10;

LL n, a[N];

int main()
{
	cin >> n;
	for(int i = 1;i <= n;i ++) cin >> a[i];
	sort(a + 1, a + 1 + n);
	int t = a[1 + n >> 1];
	LL ans = 0;
	for(int i = 1;i <= n;i ++) ans += abs(t - a[i]);
	cout << ans << endl;
	return 0;
}